package src.test06;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.DeliverCallback;
import src.util.ConnectionUtil;

/**
 * Created with IntelliJ IDEA.
 * Description: 接受者01
 * User: YKH
 * Date: 2023-08-23
 * Time: 10:38
 */
public class AccerptTopic01 {
    public static final String EXANGE_NAME = "topic_exchange";

    public static void main(String[] args) throws Exception{
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
        //声明交换机
        channel.exchangeDeclare(EXANGE_NAME, "topic");
        String QUEUE_NAME = "Q1";
        //声明队列
        channel.queueDeclare(QUEUE_NAME, false, false, false,null);
        //绑定交换机和队列
        channel.queueBind(QUEUE_NAME, EXANGE_NAME, "*.orange.*");
        System.out.println("等待接受消息");
        //开始接受消息
        DeliverCallback var3 = (consumeTag, message)->{
            System.out.println(new String(message.getBody(),"UTF-8" ));
            System.out.println("接受队列" + QUEUE_NAME + " 绑定键" + message.getEnvelope().getRoutingKey()
                                + " 交换机为" + message.getEnvelope().getExchange());


        };
        channel.basicConsume(QUEUE_NAME, true, var3, DeliverCallback->{});
    }
}
